// **************************************************************
// Com ++ Framework by the C++ World
// Please report defects: mailto:compp@cplusplusworld.com
// Please visit: http://www.cplusplusworld.com/socketlibrary.html
// **************************************************************

#include <iostream>
#include <cstdlib>
#include "ComPlusPlus/ComPlusPlus"

int main ( int argc, char *argv [] ) {

  if ( argc != 4 ) {
    std::cout << "Usage: " << argv [0] << " port GROUP IP-Addr\n";	
  	exit(1);
  }
  	
 int SPort = std::atoi ( argv[1] );	
 std::string MGS = argv [2];
 std::string Addr = argv [ 3 ];
 
try {	
  compp::SocketUdp *Srv = new compp::SocketUdp ;
  Srv->SetSockOptReuseAddress ( true);
  Srv->Bind ( Addr, SPort );
  
  char buf[1000];
  // -> Comment 1
  Srv->SetSockOptJoinMulticastGroup(MGS);
  while ( true ) {
    memset ( buf, 0, sizeof(buf));
    Srv->Recv(buf,  sizeof(buf));  
    std::cout << "---" << buf << "---\n";
  }
  return 0;
} catch ( syspp::ComException e ) {
  std::cout << "Exception " << e.what( ) << "\n" ;	
  perror ( "Multicast Test");	
}  	
}
